Parsing Packets
· 2 Bytes SYNC (0xF5 0xFA)
· 2 Bytes PID (Determines Packet Type)
· 2 Bytes Length (Length of data field)
· 0 - 24,640 Bytes Data
· 2 Bytes Checksum
1. Input packet from serial data (USB,RS232,INET)
2. Convert serial data string to U8 byte array
3. Verify Sync Bytes
3.1. Create Sync Byte array, index=0, 2 bytes
3.2. Cast the Sync Byte array to U16
3.3. Compare to 0xF5FA (Have_Sync=(0xF5FA==SyncBytes))
3.4. If Fails then Sync Error
4. Decode Packet Data Length
4.1. Create Length Byte array, index=4, 2 bytes
4.2. Cast the Length Byte array to U16
4.3. Packet Data Length=LengthBytes
4.4. Packet_Len_OK == (LengthBytes < 0x8000) -> [LEN MSB < 0x80]
4.5. If Fails then Packet Length Error
5. Verify Checksum
5.1. Get Packet Data Length
5.1.1. Create Length Byte array, index=4, 2 bytes
5.1.2. Cast the Length Byte array to U16
5.1.3. Packet Data Length=LengthBytes
5.2. Checksum Bytes to add = (6 + data length) [2SYNC+2PID+2LEN+DATA Bytes]
5.2.1. Checksum_Bytes=Checksum Bytes to add (sum this number of bytes)
5.2.2. Packet_Checksum_Index=Checksum_Bytes (index for packet checksum)
5.3. Save checksum from packet
5.3.1. Create Checksum Byte array, index=Packet_Checksum_Index, 2 bytes
5.3.2. Cast the Length Byte array to U16 (PacketChecksumBytes)
5.3.3. Packet Checksum From DPP=PacketChecksumBytes
5.4. Create U16 Array to sum
5.4.1. Get U8 subarray excluding Packet Checksum, index=0, Checksum_Bytes length
5.4.2. Create empty U8 array Checksum_Bytes length to interleave with U8 array
5.4.3. Interleave U8 arrays to create castable array
5.4.4. Calculated Checksum=Sum U16 array values
5.5. Test Checksum values
5.5.1. Add (Packet Checksum From DPP) to (Calculated Checksum)
5.5.2. AND Checksums Total with 0xFFFF (Bit Mask)
5.5.3. If Final Checksum value == 0 then Checksum Test Passed
5.6. If Fails then Checksum Error
6. Decode Packet Type
6.1. Create PID Byte array, index=0, 2 bytes
6.2. Cast the PID Byte array to U16
6.3. PID Packet Type=PIDBytes
7. Route to Packet Processing Services
· isEven = ((Int AND 0x1)==0)
· Spectrum Data Decode
· Status Decode
· Configuration Decode
· ACK Decode
· 0x8001 Status
· 0x8101 - 0x810C Spectrum (if Even, includes Status)
· 0x8207 Configuration (ASCII Command Settings)
· 0xFF?? ACK Message
1. Create Length Byte array, index=4, 2 bytes
2. Cast the Length Byte array to U16
3. Data_Length=LengthBytes
4. Channels = (Data_Length AND 0xFF00) / 3
· Get U16 PID // if PID is EVEN then Spectrum Packet has Status Data 2. HasStatus = ((PID AND 0x1)==0) // note Quick Odd/Even Comparison
1. Create Length Byte array, index=4, 2 bytes
2. Cast the Length Byte array to U16
3. Data_Length=LengthBytes
4. Spectrum_Data_Length = (Data_Length AND 0xFF00)
5. Start_Of_Status = Spectrum_Data_Length + 6
6. Status_Length = 0x40
7. Create Status Byte array, index=Start_Of_Status, Status_Length bytes
U16 RoutePacketToProcessingService(U8 PID[2])
{
U16 Service=0x0000 // no service selected, no errors
if (PID == 0x8001) {
// ((PID[0] == PID1_RCV_STATUS) && (PID[1] == PID2_SEND_DP4_STYLE_STATUS))
Service = 0x8001 // Decode Status
} elseif ((PID >= 0x8101) AND (PID <= 0x810C)) {
// (PID[0] == PID1_RCV_SPECTRUM) && ((PID[1] >= RCVPT_256_CHANNEL_SPECTRUM) && (PID[1] <= RCVPT_8192_CHANNEL_SPECTRUM_STATUS))}
Service = 0x8101 // Decode Spectrum
} elseif (PID == 0x8207) {
//((PID[0] == PID1_RCV_SCOPE_MISC) && (PID[1] == RCVPT_CONFIG_READBACK))
Service = 0x8207 // Decode Configuration
} else if (PID[0] == PID1_ACK) {
Service = 0xFF00 // ACK_PID2_ToString(BYTE PID2)
} else {
Service = 0x0002 // PID2_ACK_PID_ERROR, unknown PID
}
return Service;
}
ProcessService(U16 Service,PID)
{
switch (Service) {
case 0x8001: DecodeStatus
case 0x8101: DecodeSpectrum
case 0x8207: DecodeConfiguration
case 0xFF00: ACK_PID2_ToString(PID[1])
case 0x0002: NoService // PID error
default: NoService
}
}
(These are included below)
PID1_ACK = 0xFF
PID1_RCV_SCOPE_MISC = 0x82
PID1_RCV_SPECTRUM = 0x81
PID1_RCV_STATUS = 0x80
PID2_ACK_BAD_HEX_REC = 0x06
PID2_ACK_BAD_PARAM = 0x05
PID2_ACK_CHECKSUM_ERROR = 0x04
PID2_ACK_CP2201_NOT_FOUND = 0x09
PID2_ACK_ETHERNET_BUSY = 0x0D
PID2_ACK_FPGA_ERROR = 0x08
PID2_ACK_LEN_ERROR = 0x03
PID2_ACK_OK = 0x00
PID2_ACK_OK_ETHERNET_SHARE_REQ = 0x0C
PID2_ACK_PC5_NOT_PRESENT = 0x0B
PID2_ACK_PID_ERROR = 0x02
PID2_ACK_SCOPE_DATA_NOT_AVAIL = 0x0A
PID2_ACK_SYNC_ERROR = 0x01
PID2_ACK_UNRECOG = 0x07
PID2_SEND_DP4_STYLE_STATUS = 0x01
RCVPT_256_CHANNEL_SPECTRUM = 0x01
RCVPT_8192_CHANNEL_SPECTRUM_STATUS = 0x0C
RCVPT_CONFIG_READBACK = 0x07
ACK_PID2_ToString (Function Decodes Second ACK Parameter)
SYNC1=0xF5
SYNC2=0xFA
PID1_ACK = 0xFF
PID1_COMM_TEST = 0xF1,
PID1_RCV_SCA = 0x83,
PID1_RCV_SCOPE_MISC = 0x82,
PID1_RCV_SPECTRUM = 0x81,
PID1_RCV_STATUS = 0x80,
PID1_REQ_CONFIG = 0x20,
PID1_REQ_FPGA_UC = 0x30,
PID1_REQ_SCA = 0x04,
PID1_REQ_SCOPE_MISC = 0x03,
PID1_REQ_SPECTRUM = 0x02,
PID1_REQ_STATUS = 0x01,
PID1_VENDOR_REQ = 0xF0,
PID2_ACK_BAD_HEX_REC = 0x06,
PID2_ACK_BAD_PARAM = 0x05,
PID2_ACK_CHECKSUM_ERROR = 0x04,
PID2_ACK_CP2201_NOT_FOUND = 0x09,
PID2_ACK_ETHERNET_BUSY = 0x0D
PID2_ACK_FPGA_ERROR = 0x08,
PID2_ACK_LEN_ERROR = 0x03,
PID2_ACK_OK = 0x00,
PID2_ACK_OK_ETHERNET_SHARE_REQ = 0x0C,
PID2_ACK_PC5_NOT_PRESENT = 0x0B,
PID2_ACK_PID_ERROR = 0x02,
PID2_ACK_SCOPE_DATA_NOT_AVAIL = 0x0A,
PID2_ACK_SYNC_ERROR = 0x01,
PID2_ACK_UNRECOG = 0x07,
PID2_ARM_DIGITAL_OSCILLOSCOPE = 0x04,
PID2_AUTOSET_FAST_THRESHOLD = 0x06,
PID2_AUTOSET_INPUT_OFFSET = 0x05,
PID2_CLEAR_GP_COUNTER = 0x10,
PID2_CLEAR_SPECTRUM_BUFFER_A = 0x01,
PID2_CONFIG_READBACK_PACKET = 0x03
PID2_DISABLE_MCA_MCS = 0x03,
PID2_ENABLE_MCA_MCS = 0x02,
PID2_ERASE_FPGA_IMAGE = 0x01,
PID2_ERASE_UC_IMAGE_0 = 0x04,
PID2_ERASE_UC_IMAGE_1 = 0x05,
PID2_ERASE_UC_IMAGE_2 = 0x06,
PID2_ETHERNET_ALLOW_SHAREING = 0x20,
PID2_ETHERNET_LOCK_IP = 0x22,
PID2_ETHERNET_NO_SHARING = 0x21,
PID2_GENERIC_FPGA_WRITE = 0x89
PID2_LATCH_CLEAR_SEND_SCA = 0x03
PID2_LATCH_SEND_SCA = 0x02,
PID2_PX4_STYLE_CONFIG_PACKET = 0x01,
PID2_READ_IO3_0 = 0x07,
PID2_REINITIALIZE_FPGA = 0x03,
PID2_SEND_512_BYTE_MISC_DATA = 0x02,
PID2_SEND_CLEAR_SPECTRUM = 0x02,
PID2_SEND_CLEAR_SPECTRUM_STATUS = 0x04
PID2_SEND_DIAGNOSTIC_DATA = 0x05,8001
PID2_SEND_DP4_STYLE_STATUS = 0x01
PID2_SEND_ETHERNET_SETTINGS = 0x04,
PID2_SEND_HARDWARE_DESCRIPTION = 0x06,
PID2_SEND_I2C_DATA = 0x08,
PID2_SEND_LIST_MODE_DATA = 0x09,
PID2_SEND_NETFINDER_READBACK = 0x07,
PID2_SEND_OPTION_PA_CALIBRATION = 0x0A
PID2_SEND_SCA = 0x01,
PID2_SEND_SCOPE_DATA = 0x01,
PID2_SEND_SCOPE_DATA_REARM = 0x03,
PID2_SEND_SPECTRUM = 0x01,
PID2_SEND_SPECTRUM_STATUS = 0x03,
PID2_SET_ADC_CAL_GAIN_OFFSET = 0x0E,
PID2_SET_BOOT_FLAGS = 0x0D,
PID2_SET_DCAL = 0x0A,
PID2_SET_ETHERNET_SETTINGS = 0x11,
PID2_SET_PZ_CORRECTION_UC_TEMP_CAL_PZ = 0x0B,
PID2_SET_PZ_CORRECTION_UC_TEMP_CAL_UC = 0x0C,
PID2_SET_SERIAL_NUMBER = 0x0F,
PID2_SWITCH_TO_UC_IMAGE_0 = 0x08,
PID2_SWITCH_TO_UC_IMAGE_1 = 0x09,
PID2_SWITCH_TO_UC_IMAGE_2 = 0x0A
PID2_TEXT_CONFIG_PACKET = 0x02,
PID2_UPLOAD_PACKET_FPGA = 0x02,
PID2_UPLOAD_PACKET_UC = 0x07,
PID2_WRITE_512_BYTE_MISC_DATA = 0x09,
PID2_WRITE_IO3_0 = 0x08,
RCVPT_1024_CHANNEL_SPECTRUM = 0x05,
RCVPT_1024_CHANNEL_SPECTRUM_STATUS = 0x06,
RCVPT_2048_CHANNEL_SPECTRUM = 0x07,
RCVPT_2048_CHANNEL_SPECTRUM_STATUS = 0x08,
RCVPT_256_CHANNEL_SPECTRUM = 0x01,
RCVPT_256_CHANNEL_SPECTRUM_STATUS = 0x02,
RCVPT_4096_CHANNEL_SPECTRUM = 0x09,
RCVPT_4096_CHANNEL_SPECTRUM_STATUS = 0x0A,
RCVPT_512_BYTE_MISC_DATA = 0x02,
RCVPT_512_CHANNEL_SPECTRUM = 0x03,
RCVPT_512_CHANNEL_SPECTRUM_STATUS = 0x04,
RCVPT_8192_CHANNEL_SPECTRUM = 0x0B,
RCVPT_8192_CHANNEL_SPECTRUM_STATUS = 0x0C
RCVPT_CONFIG_READBACK = 0x07,
RCVPT_DIAGNOSTIC_DATA = 0x05,
RCVPT_DP4_STYLE_STATUS = 0x01
RCVPT_ETHERNET_SETTINGS = 0x04,
RCVPT_HARDWARE_DESCRIPTION = 0x06,
RCVPT_I2C_DATA = 0x09,
RCVPT_LIST_MODE_DATA = 0x0A,
RCVPT_LIST_MODE_DATA_FIFO_FULL = 0x0B,
RCVPT_NETFINDER_READBACK = 0x08,
RCVPT_OPTION_PA_CALIBRATION = 0x0C
RCVPT_SCA = 0x01
RCVPT_SCOPE_DATA = 0x01,
RCVPT_SCOPE_DATA_WITH_OVERFLOW = 0x03,
string ACK_PID2_ToString(BYTE PID2)
{
PID2_ToString = "";
switch (PID2) {
case PID2_ACK_OK: PID2_ToString = "ACK OK";
case PID2_ACK_SYNC_ERROR: PID2_ToString = "Sync Error"
case PID2_ACK_PID_ERROR: PID2_ToString = "PID Error"
case PID2_ACK_LEN_ERROR: PID2_ToString = "Length Error"
case PID2_ACK_CHECKSUM_ERROR: PID2_ToString = "Checksum Error"
case PID2_ACK_BAD_PARAM: PID2_ToString = "Bad Parameter"
case PID2_ACK_BAD_HEX_REC: PID2_ToString = "Bad HEX Record"
case PID2_ACK_FPGA_ERROR: PID2_ToString = "FPGA not initialized"
case PID2_ACK_CP2201_NOT_FOUND: PID2_ToString = "CP2201 not found"
case PID2_ACK_SCOPE_DATA_NOT_AVAIL: PID2_ToString = "No scope data"
case PID2_ACK_PC5_NOT_PRESENT: PID2_ToString = "PC5 not present"
case PID2_ACK_OK_ETHERNET_SHARE_REQ: PID2_ToString = "Ethernet sharing request"
case PID2_ACK_ETHERNET_BUSY: PID2_ToString = "Ethernet sharing request"
case PID2_ACK_UNRECOG: PID2_ToString = "Unknown Command"
default: PID2_ToString = "Unknown Error"
}
return PID2_ToString
}